//
//  HSDSpidermanBaseInfoHelper.m
//  GoldenCard
//
//  Created by 正合适 on 2018/3/22.
//  Copyright © 2018年 合时代. All rights reserved.
//

#import "HSDSpidermanBaseInfoHelper.h"
#import "HSDSpidermanTools.h"
#import "HSDSpidermanDefaultConfig.h"

@interface HSDSpidermanBaseInfoHelper ()

@end

@implementation HSDSpidermanBaseInfoHelper
- (instancetype)init {
    self = [super init];
    if (self) {
        _baseInfoData = [[HSDSpidermanBaseInfoData alloc] init];
        _baseInfoData.deviceInfo = [[HSDSpidermanDeviceInfoModel alloc] init];
        _baseInfoData.appInfo = [[HSDSpidermanAppinfo alloc] init];
    }
    return self;
}

- (HSDSpidermanBaseInfoData *)baseInfoData {
    return _baseInfoData;
}

- (void)startRead {
    __weak typeof(self) weakself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSLock *l = [NSLock new];
        [l lock];
        NSString *bundleIdStr = bundleId();
        weakself.baseInfoData.deviceInfo.density = @"";
        weakself.baseInfoData.deviceInfo.mac = @"";
        weakself.baseInfoData.domain = [bundleIdStr stringByReplacingOccurrencesOfString:@"." withString:@""];
        weakself.baseInfoData.appId = bundleIdStr;
        weakself.baseInfoData.appInfo.appVersion = bundleVersion();
        weakself.baseInfoData.appInfo.sdkVersionCode = [HSDSpidermanDefaultConfig sdkVersion];
        weakself.baseInfoData.appInfo.sdkVersionName = [HSDSpidermanDefaultConfig sdkName];
        weakself.baseInfoData.deviceInfo.deviceId = [HSDSpidermanTools UUID];
        weakself.baseInfoData.deviceInfo.uuid = [HSDSpidermanTools UUID];
        weakself.baseInfoData.deviceInfo.idfa = [HSDSpidermanTools IDFA];
        weakself.baseInfoData.deviceInfo.locale = [HSDSpidermanTools sysLanguage];
        weakself.baseInfoData.deviceInfo.osVersion = [HSDSpidermanTools osVersion];
        weakself.baseInfoData.deviceInfo.os = @"iOS";
        weakself.baseInfoData.deviceInfo.model = [HSDSpidermanTools iphoneType];
        weakself.baseInfoData.deviceInfo.resolution = [HSDSpidermanTools resolution];
        [l unlock];
    });

}
@end
